<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for DSA/ECDSA of X.509 ASN1 Encoder Class 'asn1x509.js'</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>


<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/rsasign-1.2.js"></script>

<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// _test/z1.*
var z1PubP8PEM = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E\n" +
"8NzY35DreQubtkWitw4xEnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQ==\n" +
"-----END PUBLIC KEY-----\n";

var z1PrvP5EPEM = "" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"Proc-Type: 4,ENCRYPTED\n" +
"DEK-Info: DES-EDE3-CBC,4626F2E5853E783F\n" +
"\n" +
"3vFpkrnbantC8RSzng2+jBw/VX95oi0VGKP0G8whENHUOVQXB/YOUSj+n80Y0Wwc\n" +
"GpeQi8U0FQdWyYv8b9aioeFB06r9t9mJsYscJ/wcIvv5tTMkr89cwN3+4GQQuqNg\n" +
"TmI9ekeoZ3NP26hTM4XTuFqHx4dzNNwjDLc8txc77WE/o4J4p8k9Py5yPZjs9EKy\n" +
"wy/yxtqQYQuFj90OMEG1G89iHTZRcq4YTZYdqg6P/XEUvyjifN+7Nym8f2N9TDDn\n" +
"RJtApPQlrgXvUDQKz6Lu1ZYMwe94E9YdutDGQMbxixbiyxlcxrkb/oEHH5WP5qPG\n" +
"w/xzh08Ce2Ftba2Q860S8nznjyZFiv+lqSKBahbujgP/63ZL+JbAd4cYBqgm4g1C\n" +
"YwMhHJbaVCzwYduxdyK2JBYEosDZiDfnOP4DqPhJYpg=\n" +
"-----END RSA PRIVATE KEY-----\n";
var z1PrvP5EPass = "hoge";

// _test/0cert_rsa/z1.prv.p5p.pem
var z1PrvP5PPEM = (function() {/*
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAOhmTdK0BSkSFWjzs5vJemLnujwJur3E8NzY35DreQubtkWitw4x
EnR7TTxBtRQkiVEV/viPedQ+rlsaTjUY/VkCAwEAAQJAeLvFTGRnlemmI8sPkSx/
n2hhcRVg5Xut4h3tL32Vefhicvq55xqycoLCdgxATa5qyKOrhSz2vNVi+a/4JHom
TQIhAP6b1FCGazJVYU/el2p2rAsdWDDdpk9TWblG2FErwSOfAiEA6atoD18F27D0
MRsOb0No9IdKEjiXnYvGAMNcbyBwfAcCIQDVSctpjcF9T+MOWoTzrehgAzwe639n
0oZGXJ/YF9RbNwIgGEm0u0RJO5idCS2ixnXfRut5C4POXpXUsuebiAF7L6kCIH0m
GpYlbUmwIMsdWH7N4Sfgk6TSs0zb/xcfNBJbWFep
-----END RSA PRIVATE KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

var z1CertPEM = "" +
"-----BEGIN CERTIFICATE-----\r\n" +
"MIIBfzCCASmgAwIBAgIBBDANBgkqhkiG9w0BAQUFADAZMQswCQYDVQQGEwJVUzEK\r\n" +
"MAgGA1UECgwBYTAeFw0xMzA1MDQyMzU5NTlaFw0xNDA1MDQyMzU5NTlaMBkxCzAJ\r\n" +
"BgNVBAYTAlVTMQowCAYDVQQKDAFiMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOhm\r\n" +
"TdK0BSkSFWjzs5vJemLnujwJur3E8NzY35DreQubtkWitw4xEnR7TTxBtRQkiVEV\r\n" +
"/viPedQ+rlsaTjUY/VkCAwEAAaNcMFowDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8E\r\n" +
"BAMCBsAwJQYDVR0fBB4wHDAaoBigFoYUaHR0cDovL2FhYS5jb20vYS5jcmwwEwYD\r\n" +
"VR0lBAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADQQAMUx/hyfWr2779id/7\r\n" +
"p6lHAFZTN+HBwfoq6c1reeVtk7JKD+18dYbKJcwbLLj2CEv04fm+MQ5p8mY7r5Aa\r\n" +
"558s\r\n" +
"-----END CERTIFICATE-----\r\n";

var z1CertIANSANPEM = "" +
"-----BEGIN CERTIFICATE-----\r\n" +
"MIIBqTCCAVOgAwIBAgIBBDANBgkqhkiG9w0BAQUFADAZMQswCQYDVQQGEwJVUzEK\r\n" +
"MAgGA1UECgwBYTAeFw0xMzA1MDQyMzU5NTlaFw0xNDA1MDQyMzU5NTlaMBkxCzAJ\r\n" +
"BgNVBAYTAlVTMQowCAYDVQQKDAFiMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOhm\r\n" +
"TdK0BSkSFWjzs5vJemLnujwJur3E8NzY35DreQubtkWitw4xEnR7TTxBtRQkiVEV\r\n" +
"/viPedQ+rlsaTjUY/VkCAwEAAaOBhTCBgjAPBgNVHRMBAf8EBTADAQH/MAsGA1Ud\r\n" +
"DwQEAwIGwDAlBgNVHR8EHjAcMBqgGKAWhhRodHRwOi8vYWFhLmNvbS9hLmNybDAT\r\n" +
"BgNVHSUEDDAKBggrBgEFBQcDAjASBgNVHRIECzAJggdhYWEuY29tMBIGA1UdEQQL\r\n" +
"MAmCB2FhYS5jb20wDQYJKoZIhvcNAQEFBQADQQDZydhz3UKmgIs4SKDKlInVOPKX\r\n" +
"njzwm83NGQZH/PRHA5esNtg284ekHIGFS6dg8ThtP1T3mon6VD78z8Z18eI0\r\n" +
"-----END CERTIFICATE-----\r\n";

// _gitpg/jsrsasign/test/eckey/k1.*
var k1PubP8PEM = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT\n" +
"CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==\n" +
"-----END PUBLIC KEY-----\n";

var k1PrvP8PPEM = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgEbVzfPnZPxfAyxqE\n" +
"ZV05laAoJAl+/6Xt2O4mOB611sOhRANCAASgFTKjwJAAU95g++/vzKWHkzAVmNMI\n" +
"tB5vTjZOOIwnEb70MsWZFIyUFD1P9Gwstz4+akHX7vI8BH6hHmBmfeQl\n" +
"-----END PRIVATE KEY-----\n";

// _work_dsa/d1.pub.p8.pem
var d1PubP8PEM = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MIIBtzCCASsGByqGSM44BAEwggEeAoGBAJ7TJ6EkB8jS3Jprk1n7xI8qMXUE8ztI\n" +
"ZhxLA3ePVbgYryGShbvN+mD2P5b1w8BnONckMqNvRtZJCg/nAjhRdnHnq9tDDE/7\n" +
"dKF/ttDOzu4o/dtJJzvNFlpSDkqXF7TSfvBvNBffap6i2jUFjxGa52rICVosRe5X\n" +
"bD3+glPzRJpPAhUAgyEkwxiCmPjW3RrYQSHC7zOl1SsCgYBxGsQFO69QKqCgmry3\n" +
"r3KIVJXh77DeEp2Tx7sW8OS4ChoQ0ECe1SvNDfC1UR9uCPdHFVF+lAbt1F148O8V\n" +
"2Ssn7zmOp7+TZfoTWRMiFJ+oRjUYfaJ38Vy8jJooQj/rIzIh5dGtNtkm0uHgx3Dz\n" +
"TcBKYW9VaFIiqbHPT47Ph8GbfgOBhQACgYEAjK/ZZUzlGBjhVGE70LFO6XT73/xa\n" +
"GYAsQwEwK8hU1eF9rw1nRaSqqORv+WtXyJNx+nLMoSoiSIIWRdH/dYaaJUmtf9EQ\n" +
"zu/qVhbQC+WUEDbhoth7vPC/vmw7Hhi6DTs69tNLrPYTJwoLX2fHhmjkuls+wKoo\n" +
"52LqH58uAWfgUjs=\n" +
"-----END PUBLIC KEY-----\n";

var d1PrvP5EPEM = "" +
"-----BEGIN DSA PRIVATE KEY-----\n" +
"Proc-Type: 4,ENCRYPTED\n" +
"DEK-Info: DES-EDE3-CBC,0A4241238121CC53\n" +
"\n" +
"SREBGTs1GdPEyT0O4MQIPfZZ59Wj8dcvqyEv+IlHzztZbqUiBfGYidu5ybhhaq8W\n" +
"FvDLUTyUPhWqjnTPI0P73t/nMFhZEEB/PWP4SCCXcsd+8ygIEVQfXl9CcFfFxsiP\n" +
"UhRBaZrU/yQ/IynKSboA/RfysHyfJTn3GcJLmMDhs7x4yZr+E8FIfk15qXCkzEsH\n" +
"yFkhDi0D23RfttXie5HiQE0e2XsB127aCkYfQ5nMesrGTVtQb+8cuodtejmGtFtT\n" +
"kslgs45yRNUznxxMi/61sm6pkH///ow0w5DN74UQsqpJj4CYhhNQY4r/QnK8SvlL\n" +
"+KFXazkFwWNZbXiyxF7zdaCsb5bglvfmJspSDGUIcxPzwMG1GQBA3IqOegjmgU/5\n" +
"LMElak/HMFFjT+jUUvxVSJIWK7f4+lWypwPkmmZib9dx8XHPpUr/vXBwPLE40fRG\n" +
"9enP7lSZRWjmW9alWIn6dpjG5HsQwH4eMxdD1fqLR7BR+nx+z47wqmAXPIzOL7PW\n" +
"N4nVxc1+juzITbT6HZB5gkHJG/5l/YFDsACK8aLHp+lgM/Onyg3cMDKSbaXERPZb\n" +
"q0MrwzdrLyCc6x9HYz2QDA==\n" +
"-----END DSA PRIVATE KEY-----\n";
var d1PrvP5EPass = "passwd";

// 0cert_rsapss/p1.prv.p5p.pem
var P1PRVPEM = (function() {/*
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAovLGMdJV4n+cBl+hDSuUd93oYG8kSFyT6dpP61pYFk6SQrz7
SfHmyAeEQLOgqK3g+cthF2qgJ1cV6IGGD0xGfBv1TsX3Z/hqIS8SVZzb+cU6IY3Z
00sRzBgjLv7RjW5uGVJppabnrh1Yb89NCL8PvzKVhppyCzm7LsPoUZ4r/otYsi55
mpUR0FN8H52w691/Zn3qBH//o+Y6tyMg8asi706Ho119VS++u4TWjrLO9mveM+as
yUzQdldVCFoUrbJlQ+N9Ro1ccpvzkXBhPITYHuz29ElFY7xuRZ+0JhJKsD7Y2by1
mlj8p8zVvxogooWbrjWNK+cFgzKE7J8KtHD4+QIDAQABAoIBAGWgmK/2CQ6sm/j1
p5J5Pa3MvuN2LeDbrHzLZdDZldrDwkDRcMBbmJ3k4j0gSvEpEQl6KOHb5Grky4sp
TR05azR4k3Q/z+AOdNKhcwPmQuPyeCD5QYOgbEcoPrlOwA8/cndkiPOBtzlGoCOL
3PW5g+6xc8RxivMpXG78TGarCbFE5JY/ef6iEIwvjR1DdcCEDqYkWa1U7nuuCPqW
+TNn0AG+5CpQIoQmCa23IWOO7tYwxZzg64UbuOq4oOjmauUeImI/lyxa9vurPFxQ
A3C1rE5pNarNN11hLqQ1kVNM8+rhCoDwnZNKTEFMbkwwtA1xVSoe/w6j6YifQMrb
c5wQ3GkCgYEAzMgonmleMNQ6xMxQEPTO+Y/LkQAlZ/XUDqb9+GWoMglMYVAPC+sX
0HU7t3Z3+rjDwuxmWMcnLlD4p41zG/S9GSe3+wEXy8nAEaxJb2v8wU5Ta+9gjJWn
11NpnyoASDos3cpuh35jUIpTJINNSa9U6n7wRgZy86Moi6xuPezeV2sCgYEAy7QV
kAvZGX1EYx5Woy850aWGUaQZFMOGeYWUWwzzbLLbno7N8Ws+D9i5vQ874PkaSPcE
Nw9Xibq8fUtbSsXNwUDsGrd8O7PHzXR8/UJTeOhj56njLymLRrTbK0N0u/oNyctB
aZ9MeEveVMXoq+vUHnR6OB3046Mhk6yd43e9XisCgYA0yDKQAiCg/VLYfsD0XeUr
NgEGMr9xeE9cJ3a2m50qqHLjcjsumz3cIRtvQj3SheUPTNdkcpCKw5wTs8XDouVK
oo4tSC7V+/5hj8Kt0Wuod4PRAjYkhj5opbtHpw/DjhsaX571lYILtFuRwbYeE+8T
MfzET805NwiwV5ViqLb2WQKBgBm6C8Mei/O5K2rtSPnhHAdLRXSIKhbCPviYE02Q
jCndSPl0hbQI3FS6BXNIOkLGkzhF4kVl7aNabzXPz57Y7oyKu4cAR3Nu2Dwtix+d
QdeSWhPHFAc/0vRCITAMm/CluxoSTpedY9YJlvHT8PfNmAOkqE7wEZ6yWqpA8cvp
soPzAoGBAMdmuggs4cs+6KD1WSErnyCQeeuTxF2aX5D+2RmvuYplD9ZGW2x8dmm2
ovMm89DQG2r3+jCkmHHHqUGwm2LjXpErxe6nQnOvYbAT3H4loz61WVBV1dqAoPpC
FQ+aCiBscr8BydE5LOr1uu6ov/8pescDPRf78d6XkJy4aKFpNv+O
-----END RSA PRIVATE KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

// 0cert_rsapss/p1.pub.p8.pem
var P1PUBPEM = (function() {/*
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAovLGMdJV4n+cBl+hDSuU
d93oYG8kSFyT6dpP61pYFk6SQrz7SfHmyAeEQLOgqK3g+cthF2qgJ1cV6IGGD0xG
fBv1TsX3Z/hqIS8SVZzb+cU6IY3Z00sRzBgjLv7RjW5uGVJppabnrh1Yb89NCL8P
vzKVhppyCzm7LsPoUZ4r/otYsi55mpUR0FN8H52w691/Zn3qBH//o+Y6tyMg8asi
706Ho119VS++u4TWjrLO9mveM+asyUzQdldVCFoUrbJlQ+N9Ro1ccpvzkXBhPITY
Huz29ElFY7xuRZ+0JhJKsD7Y2by1mlj8p8zVvxogooWbrjWNK+cFgzKE7J8KtHD4
+QIDAQAB
-----END PUBLIC KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

// ======= TEST ===============================================================

// SubjectPublicKeyInfo Test

test("SubjectPublicKeyInfo k1(EC secp256r1)", function() {
var key = KEYUTIL.getKey(k1PubP8PEM);
var obj = new KJUR.asn1.x509.SubjectPublicKeyInfo(key);
equal(obj.getEncodedHex(), "3059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425", "aaa")
});

test("SubjectPublicKeyInfo d1(DSA)", function() {
var key = KEYUTIL.getKey(d1PubP8PEM);
var obj = new KJUR.asn1.x509.SubjectPublicKeyInfo(key);
equal(obj.getEncodedHex(), "308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b", "aaa");
});
// 308201b43082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818200008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b


// newCertPEM Test


test("newCertPEM z1(RSA) signed by PKCS#5 encrypted RSA key", function() {
var prvkey = KEYUTIL.getKey(z1PrvP5EPEM, z1PrvP5EPass);
var pem = KJUR.asn1.x509.X509Util.newCertPEM(
 { serial: {int: 4},
   sigalg: "SHA1withRSA",
   issuer: {str: '/C=US/O=a'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=b'},
   sbjpubkey: z1PubP8PEM,
   ext: [
     {extname: "basicConstraints", cA: true, critical: true},
     {extname: "keyUsage", names:["digitalSignature", "nonRepudiation"]},
     {extname: "cRLDistributionPoints",
      array: [{fulluri: 'http://aaa.com/a.crl'}]},
     {extname: "extKeyUsage", array: ['clientAuth']}
   ],
   cakey: prvkey});
equal(pem, z1CertPEM, "bbb");
});

test("newCertPEM z1(RSA) signed by PKCS#5 plain RSA key", function() {
var pem = KJUR.asn1.x509.X509Util.newCertPEM(
 { serial: {int: 4},
   sigalg: "SHA1withRSA",
   issuer: {str: '/C=US/O=a'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=b'},
   sbjpubkey: z1PubP8PEM,
   ext: [
     {extname: "basicConstraints", cA: true, critical: true},
     {extname: "keyUsage", names:["digitalSignature", "nonRepudiation"]},
     {extname: "cRLDistributionPoints",
      array: [{fulluri: 'http://aaa.com/a.crl'}]},
     {extname: "extKeyUsage", array: ['clientAuth']}
   ],
   cakey: z1PrvP5PPEM});
equal(pem, z1CertPEM, "bbb");
});

test("newCertPEM p1(RSA) SHA512withRSAandMGF1", function() {
var pub = KEYUTIL.getKey(P1PUBPEM);
var prv = KEYUTIL.getKey(P1PRVPEM);
var pem = KJUR.asn1.x509.X509Util.newCertPEM(
 { serial: {int: 4},
   sigalg: "SHA512withRSAandMGF1",
   issuer: {str: '/C=US/O=a'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=b'},
   sbjpubkey: pub,
   ext: [
     {extname: "basicConstraints", cA: true, critical: true},
     {extname: "keyUsage", names:["digitalSignature", "nonRepudiation"]},
     {extname: "cRLDistributionPoints",
      array: [{fulluri: 'http://aaa.com/a.crl'}]},
     {extname: "extKeyUsage", array: ['clientAuth']}
   ],
   cakey: prv});
var hCert = pemtohex(pem);
equal(ASN1HEX.getTLVbyListEx(hCert, 0, [0]), 
      "30820221a003020102020104303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a2030201403019310b3009060355040613025553310a3008060355040a0c0161301e170d3133303530343233353935395a170d3134303530343233353935395a3019310b3009060355040613025553310a3008060355040a0c016230820122300d06092a864886f70d01010105000382010f003082010a0282010100a2f2c631d255e27f9c065fa10d2b9477dde8606f24485c93e9da4feb5a58164e9242bcfb49f1e6c8078440b3a0a8ade0f9cb61176aa0275715e881860f4c467c1bf54ec5f767f86a212f12559cdbf9c53a218dd9d34b11cc18232efed18d6e6e195269a5a6e7ae1d586fcf4d08bf0fbf3295869a720b39bb2ec3e8519e2bfe8b58b22e799a9511d0537c1f9db0ebdd7f667dea047fffa3e63ab72320f1ab22ef4e87a35d7d552fbebb84d68eb2cef66bde33e6acc94cd0765755085a14adb26543e37d468d5c729bf39170613c84d81eecf6f4494563bc6e459fb426124ab03ed8d9bcb59a58fca7ccd5bf1a20a2859bae358d2be705833284ec9f0ab470f8f90203010001a35c305a300f0603551d130101ff040530030101ff300b0603551d0f0404030206c030250603551d1f041e301c301aa018a0168614687474703a2f2f6161612e636f6d2f612e63726c30130603551d25040c300a06082b06010505070302",
      "tbs");

var x = new X509();
x.readCertPEM(pem);
equal(x.verifySignature(pub), true, "verifySignature=true");
});

test("newCertPEM z1(RSA) {subject,issuer}AltName", function() {
var prvkey = KEYUTIL.getKey(z1PrvP5EPEM, z1PrvP5EPass);
var pem = KJUR.asn1.x509.X509Util.newCertPEM(
 { serial: {int: 4},
   sigalg: "SHA1withRSA",
   issuer: {str: '/C=US/O=a'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=b'},
   sbjpubkey: z1PubP8PEM,
   ext: [
     {extname: "basicConstraints", cA: true, critical: true},
     {extname: "keyUsage", names:["digitalSignature", "nonRepudiation"]},
     {extname: "cRLDistributionPoints",
      array: [{fulluri: 'http://aaa.com/a.crl'}]},
     {extname: "extKeyUsage", array: ['clientAuth']},
     {extname: "issuerAltName", array: [{dns: 'aaa.com'}]},
     {extname: "subjectAltName", array: [{dns: 'aaa.com'}]}
   ],
   cakey: prvkey});
equal(pem, z1CertIANSANPEM, "z1CertIANSANPEM + san/ian");
});

test("newCertPEM k1(ECDSA secp256r1)", function() {
var pem = KJUR.asn1.x509.X509Util.newCertPEM(
 { serial: {int: 4},
   sigalg: "SHA256withECDSA",
   issuer: {str: '/C=US/O=a'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=b'},
   sbjpubkey: k1PubP8PEM,
   ext: [
     {extname: "basicConstraints", cA: true, critical: true},
     {extname: "keyUsage", names:["digitalSignature", "nonRepudiation"]},
     {extname: "cRLDistributionPoints",
      array: [{fulluri: 'http://aaa.com/a.crl'}]},
     {extname: "extKeyUsage", array: ['clientAuth']}
   ],
   cakey: k1PrvP8PPEM});
var hex = pemtohex(pem, "CERTIFICATE");
var tbsHex = ASN1HEX.getTLVbyList(hex, 0, [0]);
equal(tbsHex, "30820123a003020102020104300a06082a8648ce3d0403023019310b3009060355040613025553310a3008060355040a0c0161301e170d3133303530343233353935395a170d3134303530343233353935395a3019310b3009060355040613025553310a3008060355040a0c01623059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425a35c305a300f0603551d130101ff040530030101ff300b0603551d0f0404030206c030250603551d1f041e301c301aa018a0168614687474703a2f2f6161612e636f6d2f612e63726c30130603551d25040c300a06082b06010505070302", "expected tbsCert");
});

//   sigalg: {name: 'SHA1withDSA', paramempty: true},
test("newCertPEM d1(DSA)", function() {
var prvkey = KEYUTIL.getKey(d1PrvP5EPEM, d1PrvP5EPass);
var pem = KJUR.asn1.x509.X509Util.newCertPEM({
   serial: {int: 4},
   sigalg: "SHA1withDSA",
   issuer: {str: '/C=US/O=a'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=b'},
   sbjpubkey: d1PubP8PEM,
   ext: [
     {extname: "basicConstraints", cA: true, critical: true},
     {extname: "keyUsage", names:["digitalSignature", "nonRepudiation"]},
     {extname: "cRLDistributionPoints",
      array: [{fulluri: 'http://aaa.com/a.crl'}]},
     {extname: "extKeyUsage", array: ['clientAuth']}
   ],
   cakey: prvkey
});
var hex = pemtohex(pem, "CERTIFICATE");
var tbsHex = ASN1HEX.getTLVbyList(hex, 0, [0]);
equal(tbsHex, "30820282a003020102020104300906072a8648ce3804033019310b3009060355040613025553310a3008060355040a0c0161301e170d3133303530343233353935395a170d3134303530343233353935395a3019310b3009060355040613025553310a3008060355040a0c0162308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523ba35c305a300f0603551d130101ff040530030101ff300b0603551d0f0404030206c030250603551d1f041e301c301aa018a0168614687474703a2f2f6161612e636f6d2f612e63726c30130603551d25040c300a06082b06010505070302", "expected tbsCert");
});

test("newCertPEM by sighex(RSA)", function() {
var pem = KJUR.asn1.x509.X509Util.newCertPEM(
 { serial: {int: 1},
   sigalg: "SHA1withRSA",
   issuer: {str: '/C=US/O=r1'},
   notbefore: '130504235959Z',
   notafter:  '140504235959Z',
   subject: {str: '/C=US/O=r1'},
   sbjpubkey: z1PubP8PEM,
   sighex: '0102030405060708'});
var hex = pemtohex(pem, "CERTIFICATE");
var tbsHex = ASN1HEX.getTLVbyList(hex, 0, [0]);

equal(tbsHex, "3081cda003020102020101300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c027231301e170d3133303530343233353935395a170d3134303530343233353935395a301a310b3009060355040613025553310b3009060355040a0c027231305c300d06092a864886f70d0101010500034b003048024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001", "expected tbsCert");

equal(hex, "3081ea3081cda003020102020101300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c027231301e170d3133303530343233353935395a170d3134303530343233353935395a301a310b3009060355040613025553310b3009060355040a0c027231305c300d06092a864886f70d0101010500034b003048024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001300d06092a864886f70d01010505000309000102030405060708", "fake cert");
});

});

-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> |
<a href="qunit-do-x509-hex2dn.html">x509-hex2dn</a> |
<a href="qunit-do-asn1x509.html">asn1x509</a> |
<a href="qunit-do-asn1x509-newcrt.html">asn1x509-newcrt</a> |
<a href="qunit-do-asn1x509-multirdn.html">asn1x509-multirdn</a> |
</body>
</html>

